#include <head.h>

pthread_mutex_t mutex;

int con = 1;

void * pthread_Func_1(void *arg)
{
    con =0;
    
    while(1)
    {
        sleep(1);
        pthread_mutex_lock(&mutex);
        con++;
        pthread_mutex_unlock(&mutex);
    }
}
void * pthread_Func_2(void *arg){
    int temp = con;
    while(1){
        
        pthread_mutex_lock(&mutex);
        if(temp == con)
        {
            printf("con =%d\n",con);
            temp++;
        }
        pthread_mutex_unlock(&mutex);
    }
}

int main(int argc, char const *argv[])
{
    pthread_mutex_init(&mutex,NULL);
    pthread_t tid_1 = 0;
    pthread_t tid_2 = 0;
    if (pthread_create(&tid_1,NULL,pthread_Func_1,NULL) != 0)
    {
        printf("pthread_create error\n");
        exit(1);
    }
    
    if (pthread_create(&tid_2,NULL,pthread_Func_2,NULL) != 0)
    {
        printf("pthread_create error\n");
        exit(1);
    }

    pthread_join(tid_1,NULL);
    pthread_join(tid_2,NULL);
    pthread_mutex_destroy(&mutex);
    
}